﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.HtmlControls;

namespace SPThumbnailExtender.WPThumbsForWiki
{
    [ToolboxItemAttribute(false)]
    public class WPThumbsForWiki : WebPart
    {
               [WebBrowsable(true),
Personalizable(true),
Category("JQuery"),
DisplayName("Register JQuery"),
WebDisplayName("Register JQuery."),
WebDescription("Register JQuery.")]
        public bool RegisterJQuery
        {
            get
            {
                return _RegisterJQuery;
            }
            set
            {
                _RegisterJQuery = value;
            }
        }

        private bool _RegisterJQuery;


        public WPThumbsForWiki()
        {
            _RegisterJQuery = true;

        }
        protected override void CreateChildControls()
        {
            ClientScriptManager cs = this.Page.ClientScript;
            string strUrlJQuery = Page.ClientScript.GetWebResourceUrl(typeof(SPThumbnailExtender.WPThumbsForSearch.WPThumbsForSearch), "SPThumbnailExtender.jquery-1.4.3.min.js");
            string strUrlJQueryWiki = Page.ClientScript.GetWebResourceUrl(typeof(SPThumbnailExtender.WPThumbsForSearch.WPThumbsForSearch), "SPThumbnailExtender.WPThumbsForWiki.JQueryWiki.js");
            string strThumbsCSS = Page.ClientScript.GetWebResourceUrl(typeof(SPThumbnailExtender.WPThumbsForSearch.WPThumbsForSearch), "SPThumbnailExtender.ThumbsStyle.css");
            Literal lt = new Literal();
            if (_RegisterJQuery)
                lt.Text = "<script src=\"" + strUrlJQuery + "\" type=\"text/javascript\"></script>";
            lt.Text += "<script src=\"" + strUrlJQueryWiki + "\" type=\"text/javascript\"></script>";
            this.Controls.Add(lt);
            this.ChromeType = PartChromeType.None;
            HtmlHead head = (HtmlHead)Page.Header;
            HtmlLink link = new HtmlLink();
            link.Attributes.Add("href", strThumbsCSS);
            link.Attributes.Add("type", "text/css");
            link.Attributes.Add("rel", "stylesheet");
            head.Controls.Add(link);

        }
    }
}
